package com.getinsertid.sql;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.junit.Before;
import org.junit.Test;

import weaver.conn.ConnectionPool;
import weaver.conn.FastConnBuffer;
import weaver.conn.FastConnNode;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.conn.WeaverConnection;
import weaver.general.GCONST;
import weaver.servicefiles.DataSourceXML;

public class Getlocalconn {

	@Before
	public void before() {
		GCONST.setRootPath("WebContent/");
		GCONST.setServerName("ecology");
	}

	@Test
	public void getInsertId() {

//		
//		weaver.interfaces.datasource.DataSource ds = (weaver.interfaces.datasource.DataSource) 
//			    weaver.general.StaticObj.getServiceByFullname(("datasource.local"),
//			        weaver.interfaces.datasource.DataSource.class);
//		java.sql.Connection conn = ds.getConnection();

		ConnectionPool connpool = ConnectionPool.getInstance();
		WeaverConnection conn = connpool.getConnection();

		try {

			PreparedStatement ps = conn.prepareStatement("select top 1 * from hrmdepartment");
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				System.out.println(rs.getString("id"));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		String datasourceName=DataSourceXML.SYS_LOCAL_POOLNAME;
		RecordSet rs = new RecordSet();

		rs.execute("select top 1 * from hrmdepartment");
		//or   rs.executeSqlWithDataSource("select top 1 * from hrmdepartment", datasourceName);
		if (rs.next()) {
			System.out.println(rs.getString("id"));
		}
		
		// 本地数据源
		String localname = DataSourceXML.SYS_LOCAL_POOLNAME;
		RecordSetDataSource rsds = new RecordSetDataSource(DataSourceXML.SYS_LOCAL_POOLNAME);
		rsds.execute("select top 1 * from hrmdepartment");
		if (rsds.next()) {
			System.out.println(rsds.getString("id"));
		}
	}

}
